import { Button, Space } from 'antd';
import { useHistory } from 'ice';
import React from 'react';
import styles from './index.module.less';

export interface IPageHeaderProps {
  title: string;
  titleSuffix?: React.ReactNode;
  rightActionView?: React.ReactNode;
  back?: boolean | string;
}

export default function PageHeader(props: IPageHeaderProps) {
  const { title, titleSuffix, rightActionView, back = false } = props;
  const history = useHistory();

  return (
    <div className={styles['abi-page-header']}>
      <div>
        <span className="page-title">{title}</span>
        {titleSuffix}
      </div>
      {!!(rightActionView || back) && (
        <Space>
          {rightActionView}
          {back && (
            <Button
              type="primary"
              ghost
              onClick={() => {
                history.goBack();
              }}
            >
              {typeof back === 'string' ? back : '返回列表'}
            </Button>
          )}
        </Space>
      )}
    </div>
  );
}
